(function ($) {
    /* Combines fadeIn and slideDown animations */
    $.fn.fadeInAndSlideDown = function () {
        return this.animate({opacity: 'show', height: 'show'});
    };

    /* Combines fadeOut and slideUp animations */
    $.fn.fadeOutAndSlideUp = function () {
        return this.animate({opacity: 'hide', height: 'hide'});
    };
}(jQuery));

var flash = {
    /**
     * Displays a notice message and hides it after a while.
     */
    notice: function (message) {
        $('#flash-notice').queue(function () {
            $(this)
                .hide(0, function () {
                    // The text is changed here in the hide() callback so that
                    // the text would not be changed before the animation has
                    // begun.  This prevents some messages to be shown multiple
                    // times and some messages to be not shown at all, when
                    // there are many flash messages queued up.
                    $(this).text(message);
                })
                .fadeInAndSlideDown()
                .delay(3000)
                .fadeOutAndSlideUp()
                .dequeue();
        });
    }
};

$(document).ready(function () {
    $('#flash-notice:visible')
        .delay(3000)
        .fadeOutAndSlideUp();
});
